/*multhread.c*/
#include <pthread.h>
#include <stdio.h>
#include <unistd.h>
#define MAX 100
int global = 1;

void *t1_execute(void *arg)
{ // 线程1执行的代码
    while (global < MAX)
    {
        fprintf(stdout, "The global value is %d\n", global);
        fflush(stdout);
    }
}
void *t2_execute(void *arg)
{ // 线程2执行的代码
    while (global < MAX)
    {
        global = global + 1; // 改变进程变量global的值
        sleep(1);
    }
}
void main()
{
    pthread_t pid1, pid2;
    int error1, error2;
    error1 = pthread_create(&pid1, NULL, t1_execute, NULL);
    error2 = pthread_create(&pid2, NULL, t2_execute, NULL);
    pthread_join(pid2, NULL);
    pthread_join(pid1, NULL);
}